package com.supinfo.suptracking.entity;

import java.io.Serializable;
import java.util.List;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.OneToMany;

/**
 *
 * @author Fabien, Jérémy, Ludovic, Brice
 */

@Entity
public class User implements Serializable {
    
    private static final long serialVersionUID = 1L;
    
    @Id
    @GeneratedValue(strategy = GenerationType.AUTO)
    private Long id;
    
    @Column(nullable = false, unique = true)
    private String userName;
    private String firstName;
    private String lastName;
    
    @Column(name = "POSTAL_ADDRESS")
    private String postalAddress;
    private String password; // je ne sais pas s'il y a une annotation pour specifier un password.
    
    @Column(name = "CREDIT_CARD")
    private Long creditCard;
    
    @Column(name = "PHONE_NUMBER")
    private Long phoneNumber;
    
    @Column(nullable = false, unique = true)
    private String email;
    
    @Column(name = "USER_ADMIN")
    private boolean userAdmin; // TRUE = Admin
    
    @OneToMany(mappedBy = "user")
    @JoinColumn(name = "FK_CAR_LIST")
    private List<Car> carList;
    
    @OneToMany(mappedBy = "user")
    @JoinColumn(name = "FK_INVOICES_LIST")
    private List<Invoice> invoicesList;
    
    @Column(name = "ACTUAL_LATITUDE")
    private String actualLatitude;
    @Column(name = "ACTUAL_LONGITUDE")
    private String actualLongitude;

    public Long getId() {
        return id;
    }

    public void setId(Long id) {
        this.id = id;
    }

    public String getUserName() {
        return userName;
    }

    public void setUserName(String userName) {
        this.userName = userName;
    }

    public String getFirstName() {
        return firstName;
    }

    public void setFirstName(String firstName) {
        this.firstName = firstName;
    }

    public String getLastName() {
        return lastName;
    }

    public void setLastName(String lastName) {
        this.lastName = lastName;
    }

    public String getPostalAddress() {
        return postalAddress;
    }

    public void setPostalAddress(String postalAddress) {
        this.postalAddress = postalAddress;
    }

    public String getPassword() {
        return password;
    }

    public void setPassword(String password) {
        this.password = password;
    }

    public Long getCreditCard() {
        return creditCard;
    }

    public void setCreditCard(Long creditCard) {
        this.creditCard = creditCard;
    }

    public Long getPhoneNumber() {
        return phoneNumber;
    }

    public void setPhoneNumber(Long phoneNumber) {
        this.phoneNumber = phoneNumber;
    }

    public String getEmail() {
        return email;
    }

    public void setEmail(String email) {
        this.email = email;
    }

    public boolean isUserAdmin() {
        return userAdmin;
    }

    public void setUserAdmin(boolean userAdmin) {
        this.userAdmin = userAdmin;
    }

    public List<Car> getCarList() {
        return carList;
    }

    public void setCarList(List<Car> carList) {
        this.carList = carList;
    }

    public List<Invoice> getInvoicesList() {
        return invoicesList;
    }

    public void setInvoicesList(List<Invoice> invoicesList) {
        this.invoicesList = invoicesList;
    }

    public String getActualLatitude() {
        return actualLatitude;
    }

    public void setActualLatitude(String actualLatitude) {
        this.actualLatitude = actualLatitude;
    }

    public String getActualLongitude() {
        return actualLongitude;
    }

    public void setActualLongitude(String actualLongitude) {
        this.actualLongitude = actualLongitude;
    }   
    
    @Override
    public boolean equals(Object o) {
        if (this == o) return true;
        if (o == null || getClass() != o.getClass()) return false;

        User user = (User) o;

        if (email != null ? !email.equals(user.email) : user.email != null) return false;
        if (firstName != null ? !firstName.equals(user.firstName) : user.firstName != null) return false;
        return !(lastName != null ? !lastName.equals(user.lastName) : user.lastName != null);
    }

    @Override
    public String toString() {
        return "com.suptracking.entity.User[ id=" + id + " ]";
    }
}
